<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
	</head>

	<body style="padding:0px;background-color: white">
		<div id="toolbar" class="receipts_toolbar_style"></div>
		<div>
			<form id="ff" method="post">
				<table id="basicInfo" cellpadding="5" class="displaytable" style="text-align: left;">
					<tr>
						<td width="15%">
							<h id="star">* </h>库房名称</td>
						<td width="35%">
							<input class="easyui-combobox" style="width: 100%;" name="STOREHOUSE_NAME" id="input_STOREHOUSE_NAME" data-options="required:true" />
						</td>
						<td width="15%">
							<h id="star">* </h>租户名称</td>
						<td width="35%">
							<input class="easyui-combobox" style="width: 100%" name="TENANT_NAME" id="input_TENANT_NAME" data-options="required:true" />
						</td>
					</tr>
					<tr>
						<td>
							<h id="star">* </h>包库开始时间</td>
						<td>
							<input class="easyui-datebox" style="width: 100%" type="text" name="START_DATE" id="input_START_DATE" data-options="required:true" />
						</td>
						<td>
							<h id="star">* </h>包库结束时间</td>
						<td>
							<input class="easyui-datebox" style="width: 100%;" type="text" name="END_DATE" id="input_END_DATE" data-options="required:true" />
						</td>
					</tr>
					
					<tr>
						<td>
							<h id="star">* </h>包库收费</td>
						<td>
							<input class="easyui-numberbox feeinput" style="width:100%;" type="text" name="CONTRACT_FEE" id="input_CONTRACT_FEE" data-options="required:true," />
						</td>
						<td>
							<h id="star">* </h>其他收费</td>
						<td>
							<input class="easyui-numberbox feeinput" style="width:100%;" type="text" name="OTHRE_FEE" id="input_OTHRE_FEE" />
						</td>
					</tr>
					<tr>
						<td>
							<h id="star">* </h>应收总价</td>
						<td>
							<input class="easyui-numberbox" style="width:100%;" type="text" name="SUM" id="input_SUM" data-options="readonly:true,precision: 2" />
						</td>
						<td>
							<h id="star">* </h>实收总价</td>
						<td>
							<input class="easyui-numberbox" style="width:100%;" type="text" name="REAL_SUM" id="input_REAL_SUM" data-options="required:true,precision: 2" />
						</td>
					</tr>
					<tr style="display: none;">
						<td>ID</td>
						<td>
							<input class="easyui-textbox" style="width: 100%;" type="text" id="input_ID"  />
						</td>
						<td>租户编号</td>
						<td>
							<input class="easyui-textbox" style="width: 100%;" type="text" id="input_TENANT_ID" data-options="required:true" />
						</td>
						<td>库房编号</td>
						<td>
							<input class="easyui-textbox" style="width: 100%;" type="text" id="input_STOREHOUSE_ID" />
						</td>
					</tr>
				</table>
				<div id="new_footer" style="bottom: 0;">

				</div>
			</form>
		</div>
		<div id="dlg" class="hiddenDialog">
			<iframe id="ifrmEdit" style="width: 40%;height: 450px;" frameborder="0" scrolling="no"></iframe>
		</div>
	</body>

	<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
	<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../../JS/common.js"></script>
	<script type="text/javascript" src="../../../JS/finance.js"></script>
	<script type="text/javascript" src="../../../JS/FrozenShareFunction/FrozenShare.js"></script>
	<script type="text/javascript" src="../../../JS/MarketShareFunction/DialogShareFunction.js"></script>
	<script type="text/javascript">
		var currid = AddFlag;
		var id = getID();
		var content = "";
		var currPage = 0; //当前的页数
		var MaxPage = 0;
		var MinPage = 1;
		var isVerify = 0;
		var AddDialog;
		var updateData;
		$(document).ready(function(){
		if(id != AddFlag && id != undefined) {
			currid = id;
			loadRemote();
		}
		});

		getPageMaxAndMin();
		addDialogFooter($("#new_footer"));

		var receipts_type = RECEIPT_FRONT_SYMBOL;
		receipts_type += RECEIPT_NEXT_SYMBOL;
		receipts_type += RECEIPT_SAVE_SYMBOL;
		receipts_type += RECEIPT_DELETE_SYMBOL;
		receipts_type += RECEIPT_VERIFY_SYMBOL;
		receipts_type += RECEIPT_UNVERIFY_SYMBOL;
		receipts_type += RECEIPT_PRINT_SYMBOL;
		receipts_type += RECEIPT_CHARGE_SYMBOL;
		var detailData = [{
				"icon": "icon-startBoost",
				"func": "start()",
				"functionname": "开始执行"
			},
			{
				"icon": "icon-stopBoost",
				"func": "stop()",
				"functionname": "停止执行"
			}
		]
		content = AddReceiptsToolBar(receipts_type, detailData);
		$("#toolbar").append(content);
		createTenantCombobox();
		createShoreHouseCombobox();
		createIsChargeCombobox();

		function charge() {
			if(currid == AddFlag) {
				$.messager.alert("警告", "当前是新增页面，不能执行！");
				return;
			}
			var pLocation = "../TenantCharge/TenantChargeAdd.html?type=package&id=" + currid;
			$("#ifrmEdit").attr("src", pLocation);
			constructDialog($("#dlg"), "收费", ChargeDialogWidth, ChargeDialogHeight);
			AddDialog.dialog('open');
		}

		function stop() {
			HandlePageState("stop");
		}

		function start() {
			HandlePageState("start");
		}

		function HandlePageState(_type) {
			var _url = "";

			if(currid == AddFlag) {
				$.messager.alert("警告", "当前是新增页面，不能执行！");
				return;
			}
			if(isVerify === "0") {
				$.messager.alert("提示", "该单据未审核，不能执行！");
				return;
			}
			switch(_type) {
				case "start":
					_url = RemoteLinkAddress + "/frozen/contract/excuted.do";
					break;
				case "stop":
					_url = RemoteLinkAddress + "/frozen/contract/stop.do";
					break;
			}
			_data = new Object();
			_data.ORDER_NO = updateData.ORDER_NO;
			_data.ID = updateData.ID;
			_data.STOREHOUSE_ID = updateData.STOREHOUSE_ID;
			$.ajax({
				type: "post",
				url: _url,
				data: _data,
				dataType: "json",
				success: function(result) {
					if(result.msg.search("success") > -1) {
						$.messager.alert("成功", "执行成功");
					}
				},
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}

		function getPageMaxAndMin() {
			var _url = RemoteLinkAddress + "/frozen/contract/getmaxminid.do";
			$.ajax({
				type: "get",
				url: _url,
				dataType: "json",
				success: function(result) {
					if(result != null) {
						MaxPage = result.MAXID;
						MinPage = result.MINID;
						currPage = result.MINID + 1;

					}
				},
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}

		function newdata() { //新建
			currid = AddFlag;
			currPage = 0;
			resetData();
		}

		//导出
		function exportExcel() {
			if(currid === AddFlag) {
				$.messager.alert("警告", "该订单为新增订单，无法导出Excel！");
				return;
			}
			$.messager.confirm("提示", "确认导出Excel表格吗？", function(r) {
				if(r) {
					$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
						type: "get",
						data: {
							"ID": currid
						},
						url: RemoteLinkAddress + "/frozen/contract/excelorder.do",
						dataType: "json", //服务器返回的数据类型
						success: function(result) {
							window.location.href = result.path;
							//							this.onClick(location = result.path);
						}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
						error: function(xhr, status, error) {
							$.messager.alert("错误", "请求失败!");
						}
					});
				}
			});
		}

		function frontpage() { //上一张
			if(currPage > MinPage) {
				var _url = RemoteLinkAddress + '/frozen/contract/pre.do?ID=' + currPage;
				getRemoteData(_url);
			} else {
				$.messager.alert("提示", "没有上张");
			}
		}

		function nextpage() { //下一张
			if(currPage < MaxPage) {
				var _url = RemoteLinkAddress + '/frozen/contract/next.do?ID=' + currPage;
				getRemoteData(_url);
			} else {
				$.messager.alert(" 提示", "没有下张");
			}
		}

		function save() { //保存
			var isValid = isTrueData(); //检测数据完整性
			if(isValid != "验证成功") {
				$.messager.alert("警告", isValid);
				return;
			}
			var _start = $("#input_START_DATE").datebox('getValue');
			var _end = $("#input_END_DATE").datebox('getValue');
			var tip = CalTimeLimit(_start, _end, TIME_DAY);
			if(tip == -1){
				return ;
			}
			if(isVerify === "1") {
				$.messager.alert("提示", "该单据已审核，不能修改！");
				return;
			}
			if(currid != AddFlag) {
				getUpdateData();
			} else {
				getSaveData();
			}
		}

		function deletedata() { //删除
			if(isVerify === "1") {
				$.messager.alert("提示", "该单据已审核，不能删除！");
				return;
			}
			if(currid == AddFlag) {
				$.messager.alert("警告", "该页面为新增页面，不能删除！");
				return;
			}
			$.messager.confirm('Confirm', '是否删除', function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/frozen/contract/delete.do", {
							ID: currid,
							//							"AUTHORIZATION": auth,
							//							USER_ID: 'admin'
						},
						function(result) {
							if(result.msg == "success") {
								$.messager.alert({ // show success message
									title: '成功',
									msg: '删除成功'
								});
								nextpage();
							} else {
								$.messager.alert({ // show error message
									title: 'Error',
									msg: result.msg
								});
							}
						},
						'json');
				}
			});
		}

		function verifydata() { //审核
			if(isVerify == "1") {
				$.messager.alert("警告", "已经审核无须再审");
				return;
			}
			if(currid == AddFlag) {
				$.messager.alert("警告", "该页面为新增页面，不能审核！");
				return;
			}

			var _url = RemoteLinkAddress + "/frozen/contract/verify.do";
			$.ajax({
				dataType: 'JSON',
				url: _url,
				data: {
					ID: currid
				},
				type: "POST",
				success: function(result) {
					$.messager.alert("成功", "审核成功");
					isVerify = "1";
					verifyStatus_Market(isVerify, true);
				},
				error: function(result) {
					$.messager.alert("失败", "审核失败");
				}
			});
		}

		function unverifydata() { //弃审
			if(isVerify == "0") {
				$.messager.alert("警告", "已经弃审无须再弃审");
				return;
			}
			if(currid == AddFlag) {
				$.messager.alert("警告", "该页面为新增页面，不能弃审！");
				return;
			}
			$.messager.confirm("警告", "你确认要弃审该条单据吗", function(r) {
				if(r) {
					var _url = RemoteLinkAddress + "/frozen/contract/unverify.do";
					$.ajax({
						dataType: 'JSON',
						url: _url,
						data: {
							ID: currid
						},
						type: "POST",
						success: function(result) {
							$.messager.alert("成功", "弃审成功");
							isVerify = "0";
							verifyStatus_Market(isVerify, true);
						},
						error: function(result) {
							$.messager.alert("失败", "弃审失败");
						}
					});
				}
			});
		}

		function print() { //打印
			if(currid == AddFlag) {
				$.messager.alert('警示', "当前页面为新增页面，不可打印！");
				return;
			}
			var pLocation = "PackageStoreHousePrint.html?id=" + currPage;
			window.open(pLocation); /*打开pLocation中的链接html文档*/
		}

		function loadRemote() {
			var _url = RemoteLinkAddress + '/frozen/contract/findbyid.do?ID=' + currid;
			getRemoteData(_url);
		}

		function getSaveData() {
			var data = submitFormData();
			submitData(data);
		}

		function getUpdateData() {
			var data = submitFormData();
			submitData(data);
		}

		function submitData(_data) {
			lockButton("lock");
			var _url = "";
			if(currid == AddFlag) {
				_url = RemoteLinkAddress + "/frozen/contract/save.do";
			} else {
				_url = RemoteLinkAddress + "/frozen/contract/update.do";
			}
			$.ajax({
				dataType: 'JSON',
				url: _url,
				data: _data,
				type: "POST",
				success: function(result) {
					lockButton("unlock");
					var parentLocation;
					parentLocation = searchParent("PackageStoreHouseList.html");
					parentLocation.dialogClose();
					$.messager.alert("提示信息", "保存成功");
				},
				error: function(result) {
					$.messager.alert("错误信息", "保存失败");
				}
			});
		}

		function getRemoteData(_url) {
			$.ajax({
				type: "get",
				url: _url,
				dataType: "json",
				success: function(result) {
					if(result == null) {
						$.messager.alert("提示", "没有上张");
					}
					if(result != null) {
						updateData = deepCopy(result);
						isVerify = result.ISVERIFY;
						verifyStatus_Market(isVerify, true);
						currPage = result.ID;
						currid = result.ID;
						getFormData(result);
						getDialogFooterData(result);
					}
				},
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}

		function GetDateDiff(startDate, endDate) { //计算包库的时间
			var startTime = new Date(Date.parse(startDate.replace(/-/g, "/"))).getTime();
			var endTime = new Date(Date.parse(endDate.replace(/-/g, "/"))).getTime();
			var dates = Math.abs((startTime - endTime)) / (1000 * 60 * 60 * 24);
			return dates;
		}
	</script>

</html>